# -*- coding: utf-8 -*-
from flask import Blueprint, request
from werkzeug.utils import secure_filename
from utils import restful
from form.upload import imageUploadForm
import os

bp = Blueprint('/upload', __name__, url_prefix='/upload')

UPLOAD_PATH = r"C:Users\26242\Desktop\nginx-1.18.0\html\hmdp\imgs\blogs\2023"


@bp.route('/blog', methods=['POST'])
def upload_blog_image():
    form = imageUploadForm(request.files)
    if not form.validate():
        return restful.fail(form.errors)
    images = form.file.data
    filename = secure_filename(images.filename)
    images.save(os.path.join(UPLOAD_PATH, filename))
    return restful.success(data=os.path.join('/blogs/2023', filename))

@bp.route('/blog/delete', methods=['GET'])
def delete_image():
    # 删除直接返回成功，不做删除
    return restful.success()
